package com.handpay.zztong.hp.config;

import com.handpay.framework.SecureManager;

public class ZZTConfig {
    public static String HPZZT_URL,// 帐帐通协议url
            HPZZT_USERINFO_URL,// 帮助URL
            HPZZT_TRANS_URL, // 卡卡转账URL
            HPZZT_SUPERTRANS_URL, // 快速转账URL
    //            HPZZT_UINPAYTRANS_URL = "http://www.handpay.com.cn/web/newzzt/2.0/unionpaytransfer.html",//银联转账说明URL
    HPZZT_SAMETRANS_URL; // 同名转账URL
    // 帐帐通服务地址
    public static String APPSERVER; // 生产
    // 渠道
    public static String CHANNEL;
    // 版本升级渠道
    public static String UPDATE_CHANNEL;
    //友盟UMENG_APPKEY
    public static final String UMENG_APPKEY = "54eec5f6fd98c5300a000518";
    // 协议版本号
    public static String HPVIRSION;
    public static boolean testData = false;
    public static String PHONE;
    public static String QB;
    public static String GAME;
    public static boolean isUseHTTPS = false;
    public static final String URL_PATH = "hpayMicroView/";

//    public enum BankConfig {
//
//        // 支持的银行,请注意bankId要与后台的bankId一一对应
//        ABC("02", R.string.abc_bank, R.array.abccardbin, R.drawable.abc), CMBC("01", R.string.cmbc_bank, R.array.cmbccardbin, R.drawable.cmbc);
//        // JSH("03", R.string.jsh_bank, R.array.jshcardbin, R.drawable.jsh);
//        // 银行ID
//        final public String mBankId;
//        // 银行名称
//        final public int mBankName;
//        // 银行对应的cardbin数组的资源id
//        final public int mCardbinArray;
//        // 银行对应的logo的资源Id
//        final public int mLogoId;
//
//        BankConfig(String bankId, int bankName, int cardBinArray, int logoId) {
//            mBankId = bankId;
//            mBankName = bankName;
//            mCardbinArray = cardBinArray;
//            mLogoId = logoId;
//        }
//    }

    // for test
    public static boolean isTesting = false;
    public static final boolean isTestLocation = false;//是否允许输入经纬度。
    public static final boolean isTestSelectLocation = false;
    public static String testerCsn = "";
    public static boolean SELECT_DEVICE_TYPE = true;
    public static TestEnv ENV;
    public static String SECRETKEY = null;

    static {
        System.loadLibrary("hp_native");
        String[] strings = stringsFromJNI();
        APPSERVER = strings[0]; // 生产环境网址
        CHANNEL = strings[1]; // 渠道号
        HPVIRSION = strings[2]; // 协议版本号
        SecureManager.sMod = strings[3];
        SecureManager.sPubExp = strings[4];
        HPZZT_URL = strings[5];
        HPZZT_USERINFO_URL = strings[6];
        HPZZT_TRANS_URL = strings[7];
        HPZZT_SUPERTRANS_URL = strings[8];
        HPZZT_SAMETRANS_URL = strings[9];
        UPConfig.UPTestHost = strings[10];
        UPConfig.UPProHost = strings[11];
        UPConfig.PREV_QUERY_BANKCARD = strings[12];
        UPConfig.PREV_DELETE_BANKCARD = strings[13];

        ENV = new TestEnv(strings[15], 80, HPVIRSION, CHANNEL, "", false, true); // PRODUCT
//        ENV = new TestEnv("10.148.181.173", 8080, HPVIRSION, CHANNEL, "", true, true);
//        ENV = new TestEnv("10.148.181.173", 8080, HPVIRSION, CHANNEL, "", true, true);

        // 1表示需要选择
        if ("1".equals(strings[16])) {
            SELECT_DEVICE_TYPE = true;
        } else {
            SELECT_DEVICE_TYPE = false;
        }
        UPDATE_CHANNEL = strings[17];
        getKey();
        testerCsn = ENV.CSN;
        if (!APPSERVER.contains(ENV.SERVER)) {
            UPConfig.UPHost = UPConfig.UPTestHost;
        } else {
            UPConfig.UPHost = UPConfig.UPProHost;
        }
        PHONE = strings[18];
        QB = strings[19];
        GAME = strings[20];
    }

    public native static String[] stringsFromJNI();

    // 上传二进制，而不是HEX
    public static final boolean UPLOAD_BIN = true;
    // 是否可以降级交易。true表示可以,false表示不可以
    public static boolean DW_TRADE = true;
    // 是否激活Activity
    public static boolean isActive = false;
    // 屏幕变暗变亮的记录
    public static boolean isScreenLight = false;

    public static class TestEnv {
        // 服务端地址
        public String SERVER;
        // 服务端口号
        public int PORT;
        // 服务版本号
        public String HPV;
        // 使用的csn
        public String CSN;
        // 是否允许自己设置配置
        public boolean CANSET;
        // 是否使用刷卡器csn
        public boolean SWIPERCSN;
        // 渠道号
        public String CHAN;
        // 标志余额查询，使用银联与否
        public boolean BALANCE_ENQUIRE_UP;
        // 是否打印log
        public boolean PRINTLOG = false;
        // 是否需要替换地址
        public boolean REPLACEDOMAIN = false;

        TestEnv(String ser, int port, String hpversion, String channel, String csn, boolean canSet, boolean useSwiperCsn) {
            SERVER = ser;
            PORT = port;
            HPV = hpversion;
            CHAN = channel;
            CSN = csn;
            CANSET = canSet;
            SWIPERCSN = useSwiperCsn;
            BALANCE_ENQUIRE_UP = false;
            // 非生产地址，打印log，并设置银联测试地址；生产地址，不打印log，设置银联生产地址
            if (!APPSERVER.contains(ser)) {
                PRINTLOG = true;
                isUseHTTPS = false;
                isTesting = true;
            } else {
                PRINTLOG = true;
                isUseHTTPS = true;
                isTesting = false;
            }
        }
    }

    private static void getKey() {
        if (UPDATE_CHANNEL.length() > 8) {
            SECRETKEY = UPDATE_CHANNEL.substring(0, 8);
        } else if (UPDATE_CHANNEL.length() == 8) {
            SECRETKEY = UPDATE_CHANNEL;
        } else {
            StringBuffer sb = new StringBuffer(UPDATE_CHANNEL);
            for (int i = 0; i < 8 - UPDATE_CHANNEL.length(); i++) {
                sb.append(i);
            }
            SECRETKEY = sb.toString();
        }
    }
}